import { NetInfo } from 'react-native';
import ToastUtil from './ToastUtil';

const LoadingUtil = {
  showLoading() {
    global.mLoadingComponentRef && global.mLoadingComponentRef.show();
  },

  showNetLoading() {
    global.mLoadingComponentRef && global.mLoadingComponentRef.show();
    // setTimeout(()=>{
    NetInfo.isConnected.fetch().done((isConnected) => {
      if (!isConnected) {
        this.dismissLoading();
        ToastUtil.showOffline('请检测网络连接');
      }
    });
    // },10000);
  },

  dismissLoading() {
    global.mLoadingComponentRef && global.mLoadingComponentRef.close();
  },
};

export default LoadingUtil;
